package net.keebook.webapp.ws;

import java.io.IOException;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;

import net.keebook.webapp.dao.PasswordResetRequestDao;
import net.keebook.webapp.dao.SettingDao;
import net.keebook.webapp.util.SettingId;

import org.apache.log4j.Logger;


@Path("/resetpassword/{id}")
@Stateless
public class ResetPasswordService extends WebService {
	@EJB
	private SettingDao settingDao;
	@Inject
	private PasswordResetRequestDao passwordResetRequestDao;
	
	@GET
	public void saveSettings(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("id") String exposableId) throws IOException {
		String root = getSettingDao().get(SettingId.PUBLIC_URL).getValue();
		if (!root.endsWith("/")) {
			root += "/";
		}
		
		Logger.getLogger(this.getClass()).info("Processed password reset request for id: " + exposableId);
		response.sendRedirect(root + "resetpassword2.xhtml?id="+exposableId);
	}

	public SettingDao getSettingDao() {
		return settingDao;
	}

	public void setSettingDao(SettingDao settingDao) {
		this.settingDao = settingDao;
	}

	public PasswordResetRequestDao getPasswordResetRequestDao() {
		return passwordResetRequestDao;
	}

	public void setPasswordResetRequestDao(PasswordResetRequestDao passwordResetRequestDao) {
		this.passwordResetRequestDao = passwordResetRequestDao;
	}
}
